/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package control;

import model.Ansat;
import view.GUI;

/**
 *
 * @author Morten J, Morten B & Jonas
 */
public class LogindHandler {

    private String user;
    private char[] pw;
    private boolean firstAnsat;

    public LogindHandler() {
        firstAnsat = true;
    }

    public void validateLogin(int user, char[] pw) {
        this.pw = pw;
        String passString = new String(this.pw);
        String errorMessage = "Brugernavn og kodeord stemmer ikke overens";

        for (Ansat ah : AnsatHandler.getAnsatListe()) {
            if (ah.getAnsatNr() == user && ah.getKodeord().equals(passString)) {
                if (!firstAnsat) {
                    if (AnsatHandler.getAktuelAnsat().getAnsatNr() != user) {
                        GUI.getGuiHandler().clearKasse();
                    }
                }
                GUI.getGuiHandler().showKasse();
                GUI.getGuiHandler().setNavVisible(true);
                AnsatHandler.setAktuelAnsat(ah);
                GUI.getGuiHandler().setAnsatNavn();
                errorMessage = "";
                firstAnsat = false;
            }
        }
        GUI.getGuiHandler().focusKasse();
        GUI.getGuiHandler().setLoginFeedback(errorMessage);
    }
}
